<?php

namespace app\xwam\controller;

/**
 * CustomConf 控制器类
 *
 * @version VER:1.0; DATE:2016-5-26; AUTHOR:SoChishun; EMAIL:14507247@qq.com; DESC:Added.
 * @version 1.1 2016-8-22 SoChishun 由CustomConf重命名为SysUserDictController
 */
class SysUserDictController extends AppbaseController {

    function conf_list_search() {
        $search = input('param.');
        if ($search['word']) {
            $where['_string'] = sprintf("title like '%s'", $search['word'], $search['word']);
        }
        // $where['site_id'] = $this->site_id;
        $where['conf_group'] = $search['group'];
        return array('where' => $where, 'search' => $search);
    }

    function conf_list($group = '') {
        if (!$group) {
            exit('参数无效');
        }
        $asearch = $this->conf_list_search();
        $m_conf = new \app\xwam\model\UserDictModel();
        $list = $m_conf->selectPaging($page, array('where' => $asearch['where'], 'order' => 'sort, id desc'), array('page_params' => $asearch['search']));
        $this->assign('list', $list);
        $this->assign('page', $list->render());
        $this->assign('search', $asearch['search']);
        return view();
    }

    function conf_edit($id = '', $group = '') {
        $data = array();
        $m_conf = new \app\xwam\model\UserDictModel();
        if ($id) {
            $data = $m_conf->find($id);
        }
        if (!$data) {
            $data = array('conf_group' => $group, 'site_id' => $this->siteId, 'user_name' => $this->userName);
        }
        $this->assign('data', $data);
        return view();
    }

    function conf_edit_save() {
        $m_conf = new \app\xwam\model\UserDictModel();
        $result = $m_conf->saveConf();
        $this->dialogJump($result['status'], $result['info']);
    }

    function conf_delete($id = '') {
        $m_conf = new \app\xwam\model\UserDictModel();
        $result = $m_conf->deleteConf($id);
        return json_encode($result);
    }

    function changeStatus($id, $status) {
        $m_conf = new \app\xwam\model\UserDictModel();
        return json_encode($m_conf->changeStatus($id, $status));
    }

    function changeSort($id, $sort) {
        $m_conf = new \app\xwam\model\UserDictModel();
        return json_encode($m_conf->changeSort($id, $sort));
    }

}
